package cn.t.enums.device;


import cn.t.core.enums.Enumer;
import cn.t.core.enums.base.CommonEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import javax.validation.ValidationException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author l
 */
@Enumer
@Getter
@AllArgsConstructor
public enum DeviceTypeEnum implements CommonEnum<Integer, String> {

    GRAVITY_DOOR_CABINET(1, "重力开门柜"),
    NO_GRAVITY_GRID_CABINET(3, "无重力格口柜"),
    ROTATING_CABINET(7, "旋转柜");
public static final List<Integer> ALL_TYPE_JOB = Arrays.asList(GRAVITY_DOOR_CABINET.getCode());
    @JsonValue
    @EnumValue
    private final Integer code;
    private final String name;

    public static String combineName(List<Integer> codes, String delimiter) {
        List<String> names = new ArrayList<>();
        codes.forEach(code -> Arrays.stream(DeviceTypeEnum.values()).filter(f -> f.getCode().equals(code)).findFirst().ifPresent(f -> names.add(f.getName())));

        return String.join(delimiter, names);
    }

    public static String getName(Integer code) {
        return Arrays.stream(DeviceTypeEnum.values()).filter(f -> f.getCode().equals(code)).findFirst()
                .orElseThrow(() -> new ValidationException("非法code:" + code)).name;
    }
}